#!/usr/bin/perl
#-----------------------------------------------------------+
#                                                           |
# Unix2Dos.pl                                               |
#                                                           |
#-----------------------------------------------------------+
#                                                           |
#  AUTHOR: James C. Estill                                  |
# CONTACT: JamesEstill_@_gmail.com                          |
# STARTED: 07/26/2004                                       |
# UPDATED: 07/11/2007                                       |
#                                                           |
# DESCRIPTION:                                              |
#  Converts Unix formatted text files to DOS format.        |
#                                                           |
# Example Usage:                                            |
#  Unix2Dos.pl InFile Outfile                               |
#                                                           |
#-----------------------------------------------------------+

my $infile = shift or die $usage;
my $outfile = shift or die $usage;

print "Starting Unix2Dos for $infile.\n";

Unix2Dos ( $infile, $outfile);

print "Unix2Dos has completed.";

exit;

#-----------------------------------------------------------+
# SUBFUNCTIONS                                              |
#-----------------------------------------------------------+

sub Unix2Dos {
    
    # Path of the file in UNIX Format
    my $FileIn = $_[0];
    my $FileOut = $_[1];

    # Original dos line
    my $dos = "\012\015";
    my $unix = "\n";
    # Start lineNo at zero
    $lineNo = 0;

    open( IN, $FileIn)  || die ("\n Can not read $FileIn \n");
    open( OUT, ">".$FileOut) || die ("\n Can not write $FileOut \n");

    while( <IN>){
       $lineNo++;
       $line = $_;
       # Use the regular expression search operator to replace unix
       $line =~ s/$unix/$dos/g;
       print OUT "$line";
       print "$lineNo \n";
    }
    close(IN);
    close(OUT);

    print "Conversion is complete. \n";

}

#-----------------------------------------------------------+
# HISTORY                                                   |
#-----------------------------------------------------------+
# 07/11/2007
# - Modified code format for jperl .. added jperl style header
